package com.kupurui.asteacher.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.frame.adapter.CommonAdapter;
import com.android.frame.adapter.ViewHolder;
import com.android.frame.view.linearlistview.LinearListView;
import com.facebook.drawee.view.SimpleDraweeView;
import com.kupurui.asteacher.R;
import com.kupurui.asteacher.bean.MistakesInfo;
import com.kupurui.asteacher.ui.ShowBigImageAty;
import com.kupurui.asteacher.utils.URLImageParser;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/21.
 */

public class MistakesRadioAdapter extends CommonAdapter<MistakesInfo> {
    List<String> uris = new ArrayList<>();

    MistajesChildAdapter adapter;

    public MistakesRadioAdapter(Context context, List<MistakesInfo> mList, int itemLayoutId) {
        super(context, mList, itemLayoutId);
    }

    @Override
    public void convert(ViewHolder holder, final MistakesInfo item, int positon) {
        LinearListView listView = holder.getView(R.id.listview);
        holder.setTextViewText(R.id.tv_source,"来源："+item.getLaiyuan());
        TextView tvTitle= holder.getView(R.id.tv_title);
        tvTitle.setText(Html.fromHtml(item.getTitle(), new URLImageParser(mContext,tvTitle), null));
        TextView tvSubject = holder.getView(R.id.tv_subject);
        LinearLayout llRadioAnswer = holder.getView(R.id.ll_radio_answer);
        LinearLayout llQuestion = holder.getView(R.id.ll_question);
        SimpleDraweeView ivStudentAnswer = holder.getView(R.id.iv_student_answer);
        TextView tvCorrect = holder.getView(R.id.tv_correct);
        TextView tvMistake = holder.getView(R.id.tv_mistake);
        if (item.getQ_type().equals("1")){
            tvSubject.setText((positon+1)+".单选题");
            llRadioAnswer.setVisibility(View.VISIBLE);
            listView.setVisibility(View.VISIBLE);
            adapter = new MistajesChildAdapter(mContext,item.getAnswer(),R.layout.radio_item);
            listView.setAdapter(adapter);
            llQuestion.setVisibility(View.GONE);
            tvCorrect.setText(item.getCorrect());
            if (TextUtils.isEmpty(item.getMistake())){
                tvMistake.setText("无");
            }else {
                tvMistake.setText(item.getMistake());
            }
        }else if(item.getQ_type().equals("2")){
            tvSubject.setText((positon+1)+".判断题");
            llRadioAnswer.setVisibility(View.VISIBLE);
            listView.setVisibility(View.VISIBLE);
            adapter = new MistajesChildAdapter(mContext,item.getAnswer(),R.layout.radio_item);
            listView.setAdapter(adapter);
            llQuestion.setVisibility(View.GONE);
            tvCorrect.setText(item.getCorrect());
            if (TextUtils.isEmpty(item.getMistake())){
                tvMistake.setText("无");
            }else {
                tvMistake.setText(item.getMistake());
            }
        }else if(item.getQ_type().equals("3")){
            tvSubject.setText((positon+1)+".填空题");
            listView.setVisibility(View.GONE);
            llRadioAnswer.setVisibility(View.GONE);
            llQuestion.setVisibility(View.VISIBLE);
            ivStudentAnswer.setImageURI(item.getContent());
        }else if(item.getQ_type().equals("4")){
            tvSubject.setText((positon+1)+".解答题");
            listView.setVisibility(View.GONE);
            llRadioAnswer.setVisibility(View.GONE);
            llQuestion.setVisibility(View.VISIBLE);
            ivStudentAnswer.setImageURI(item.getContent());
        }

        ivStudentAnswer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                uris.clear();
                uris.add(item.getContent());
                Bundle bundle1 = new Bundle();
                bundle1.putStringArrayList("pics",new ArrayList<>(uris));
                Intent intent = new Intent();
                intent.setClass(mContext,ShowBigImageAty.class);
                intent.putExtras(bundle1);
                mContext.startActivity(intent);
            }
        });

    }
}
